package com.ming.easyDevelop.controller;

import com.ming.easyDevelop.controller.base.BaseController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.ming.easyDevelop.service.AddressesService;
import com.ming.easyDevelop.controller.base.ValidListBean;
import javax.validation.Valid;
import com.ming.easyDevelop.entity.po.Addresses;
import com.ming.easyDevelop.entity.vo.ResponseVo;
import com.ming.easyDevelop.entity.query.AddressesQuery;
import java.util.List;
/**
 * @Description  Controller API
 * @Author ming
 * @Date 2024/07/10
 */
@RequestMapping("/api/addresses")
@RestController
public class AddressesController extends BaseController {
	@Resource
	private AddressesService addressesService;

	@RequestMapping("/list")
	public ResponseVo getDataList(AddressesQuery query){
		return getSuccessResponseVo(this.addressesService.findListByParam(query));
	}
	@PostMapping("/add")
	public ResponseVo add(@Valid @RequestBody Addresses bean){
		this.addressesService.add(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdate")
	public ResponseVo addOrUpdate(@Valid @RequestBody Addresses bean){
		this.addressesService.addOrUpdate(bean);
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addBatch")
	public ResponseVo addBatch(@RequestBody ValidListBean<Addresses> list){
		this.addressesService.addBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	@PostMapping("/addOrUpdateBatch")
	public ResponseVo addOrUpdateBatch(@RequestBody ValidListBean<Addresses> list){
		this.addressesService.addOrUpdateBatch(list.getData());
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据AddressID查询
	 */
	@GetMapping("/addressID")
	public ResponseVo getByAddressID(Integer addressID){
		return getSuccessResponseVo(this.addressesService.getByAddressID(addressID));
	}

	/**
	 * 根据AddressID更新
	 */
	@PutMapping("/addressID")
	public ResponseVo updateByAddressID(@Valid Addresses bean, Integer addressID){
		this.addressesService.updateByAddressID(bean,addressID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据AddressID删除
	 */
	@DeleteMapping("/addressID")
	public ResponseVo deleteByAddressID(Integer addressID){
		this.addressesService.deleteByAddressID(addressID);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据UserIDAndAddressType查询
	 */
	@GetMapping("/userIDAndAddressType")
	public ResponseVo getByUserIDAndAddressType(Integer userID, String addressType){
		return getSuccessResponseVo(this.addressesService.getByUserIDAndAddressType(userID, addressType));
	}

	/**
	 * 根据UserIDAndAddressType更新
	 */
	@PutMapping("/userIDAndAddressType")
	public ResponseVo updateByUserIDAndAddressType(@Valid Addresses bean, Integer userID, String addressType){
		this.addressesService.updateByUserIDAndAddressType(bean,userID, addressType);
		return getSuccessResponseVo(null);
	}

	/**
	 * 根据UserIDAndAddressType删除
	 */
	@DeleteMapping("/userIDAndAddressType")
	public ResponseVo deleteByUserIDAndAddressType(Integer userID, String addressType){
		this.addressesService.deleteByUserIDAndAddressType(userID, addressType);
		return getSuccessResponseVo(null);
	}

}